<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf8" language="java" %>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf8">
    <title><spring:message code="label.complaints"/></title>
    <link rel="stylesheet" type="text/css" href="<c:url value="/resources/bootstrap/css/bootstrap.min.css"/>"/>
    <script src="<c:url value='/resources/bootstrap/js/bootstrap.min.js'/>"></script>
    <script src="<c:url value='/resources/scripts/jquery.min.js'/>"></script>

    <script>
        $(document).ready(function () {

            $("#navTabs li").click(function () {
                $("#navTabs li").removeClass('active');
                $(this).addClass("active");
                $(".tab-pane").hide();
                var selected_tab = $(this).find("a").attr("href");
                var starting = selected_tab.indexOf("#");
                var sub = selected_tab.substring(starting);
                $(sub).fadeIn();
                return false;
            });
        });

    </script>
</head>
<body>
<%@include file="/WEB-INF/views/header.jsp" %>

<div class="panel panel-default">
    <div class="panel-heading">
        <h1><spring:message code="label.menu"/></h1>
    </div>

    <div class="panel-body">

        <ul id='navTabs' class="nav nav-tabs">
            <li class="active">
                <a href="#all" data-toggle="tab">
                    All Complaints
                </a>
            </li>
            <c:if test="${authenticated}">
                <li>
                    <a href="#my" data-toggle="tab">
                        My Complaints
                    </a>
                </li>
            </c:if>
        </ul>
        <div id='myTabContent' class="tab-content">
            <div id='all' class="tab-pane fade in active">
                <c:if test="${!empty allcomplaints}">
                    <table class="table table-hover">
                        <thead>
                        <tr>
                            <th><spring:message code="label.publishDate"/></th>
                            <th><spring:message code="label.subject"/></th>
                            <th><spring:message code="label.description"/></th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${allcomplaints}" var="complaint">
                            <tr onclick="window.location='<c:url value='/complaint?id=${complaint.id}'/>'">
                                <td><fmt:formatDate value="${complaint.publishDate}" pattern="dd/MM/yyyy"/></td>
                                <td>${complaint.subject}</td>
                                <td>${complaint.description}</td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </c:if>
            </div>

            <div id='my' class="tab-pane fade in">
                <c:if test="${!empty mycomplaints}">
                    <table class="table table-hover">
                        <thead>
                        <tr>
                            <th><spring:message code="label.publishDate"/></th>
                            <th><spring:message code="label.subject"/></th>
                            <th><spring:message code="label.description"/></th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${mycomplaints}" var="complaint">
                            <tr onclick="window.location='<c:url value='/complaint?id=${complaint.id}'/>'">
                                <td><fmt:formatDate value="${complaint.publishDate}" pattern="dd/MM/yyyy"/></td>
                                <td>${complaint.subject}</td>
                                <td>${complaint.description}</td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </c:if>
            </div>
        </div>
        <div class="form-group">
            <div class="btn-group btn-group-sm">
                <button onclick="window.location='<c:url value='/complaint'/>'" class="btn btn-default">
                    <spring:message code="label.complaint.create"/>
                </button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
